<template>
  <div class="app-container">
    <div class="search-container">
      <div class="search-wrapper">
        <div class="debenture-search">
          <el-form ref="form" :model="searchValvationVo" label-width="80px" >
            <el-form-item label="债券代码">
              <el-col :span="11">
                <el-input v-model="searchValvationVo.debentureCode" placeholder="债券代码" style="width: 70%;"/>
              </el-col>
              <el-col :span="11">
                <el-form-item label="查询日期">
                  <el-date-picker v-model="searchValvationVo.valueDate" type="date" value-format="yyyy-MM-dd" placeholder="查询日期" style="width: 70%;">李四</el-date-picker>
                </el-form-item>
              </el-col>
            </el-form-item>
            <el-form-item label="债券名称">
              <el-col :span="11">
                <el-input v-model="searchValvationVo.debentureName" placeholder="债券名称" style="width: 70%;"/>
              </el-col>
              <el-col :span="11">
                <el-button class="sreach-button" type="primary" @click="onSubmit()">搜索</el-button>
              </el-col>
            </el-form-item>
          </el-form>
        </div>
      </div>
    </div>
    <el-table
      :row-class-name="tableRowClassName"
      :data="tableData"
      style="width: 100%">
      <el-table-column
        prop="debentureCode"
        label="债券代码"
        width="200"/>
      <el-table-column
        prop="debentureName"
        label="债券名称"
        width="200"/>
      <el-table-column
        prop="valueDate"
        label="估值日期"
        width="200"/>
      <el-table-column
        prop="valuation"
        label="估值"
        width="200"/>
      <el-table-column
        prop="address"
        label="操作">
        <template slot-scope="scope">
          <el-button type="text" size="small" @click="handleClick(scope.row.id)" >编辑</el-button>
          <el-button type="text" size="small" @click="deleteOne(scope.row.id)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      :current-page.sync="page"
      :total="total"
      :page-size="limit"
      class="pagination"
      layout="prev, pager, next"
      @current-change="handleCurrentChange"/>
  </div>
</template>

<script>
import valuation from '@/api/valuation'
export default {
  data() {
    return {
      form: {
        name: '',
        region: '',
        date1: '',
        date2: '',
        delivery: false,
        type: [],
        resource: '',
        desc: ''
      },
      financialInstrumentsValuation: {},
      tableData: [],
      searchValvationVo: {},
      page: 1, // 当前页
      limit: 10, // 每页个数
      total: 1 // 总页码
    }
  },
  created() {
    this.handleClick()
  },
  methods: {
    onSubmit() {
      valuation.pageBySearch(this.page, this.limit, this.searchValvationVo).then(response => {
        this.tableData = response.data.records
        this.total = response.data.total
      })
    },
    onCancel() {
      this.$message({
        message: 'cancel!',
        type: 'warning'
      })
    },
    handleCurrentChange(val){
      this.page = val;
      this.handleClick();
    },
    handleClick() {
      valuation.page(this.page, this.limit).then(response => {
        this.tableData = response.data.records
        this.total = response.data.total
      })
    }
  }
}
</script>

<style scoped>
.search-input{
  margin-left: 900px;
}
.sreach-button{
  margin-left: 60px;
}
.search-container{
  margin-left: 100px;
}
</style>

